function $sk(obj){
	return document.getElementById(obj);
}

var skin={};

skin.addEvent=function(){
	var skins =$sk("skin").getElementsByTagName("li");
	for (i=0;i<skins.length;i++)
	{
		skins[i].onclick=function(){skin.setSkin(this.id.substring(5))};
	}
}

skin.setCookie=function(n){
	var expires=new Date();
	expires.setTime(expires.getTime()+24*60*60*365*1000);
	var flag="Skin_Cookie="+n;
	document.cookie=flag+";expires="+expires.toGMTString();
}

skin.readCookie=function(){
    var skin=0
    var mycookie=document.cookie;
    var name="Skin_Cookie";
    if(mycookie.indexOf(name+"=")==-1){
        skin=0;
    }
    else{
        var values=mycookie.split(name+"=")[1].split(";")[0];
        if (values!=null)
        {
            skin=values;
        }
        else{
            skin=0;        
        }
    }
    return skin;
    
}

skin.setSkin=function(n){
	var skins =$sk("skin").getElementsByTagName("li");
	for (i=0;i<skins.length;i++)
	{
		skins[i].className="";
	}
	skin.setCookie(n);
	$sk("skin_"+n).className="selected";
	$sk("cssfile").href="/themes/twitter/css/style"+n+".css";
}

window.onload=function(){
	skin.setSkin(skin.readCookie());
	skin.addEvent();
}